﻿using EA.Common;
using EA.DTO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EA.DAO
{
    public class ProductCategoryDA: ObjectDA
    {
        public ProductCategoryDA(String connection_string)
            : base(connection_string)
        {

        }
        public DataTable GetListProductCategorry()
        {
            String query = "SELECT  * FROM ProductCategory WHERE status <> "+Constant.PRODUCT_CATEGORY_DELETE;
            DataTable table = new DataTable();
            this.Fill(query, null, table);
            return table;
        }

        public DataTable GetProductCategoryByID(int ID)
        {
            String query = "SELECT * FROM ProductCategory WHERE ID=@ID";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@ID", ID);
            DataTable table = new DataTable();
            this.Fill(query, param, table);
            return table;
        }
        
        public Boolean InsertProductCategory(ProductCategoryTO productCategory)
        {
            String query = "INSERT INTO ProductCategory(Name,CreateDate,Status) VALUES(@Name,@CreateDate,@Status)";
            SqlParameter[] param = new SqlParameter[3];
            param[0] = new SqlParameter("@Name",productCategory.Name);
            param[1] = new SqlParameter("@CreateDate",productCategory.CreateDate);
            param[2] = new SqlParameter("@Status", productCategory.Status);
            return this.ExecuteNonQuery(query,param);
        }

        public Boolean DeleteProductCategory(int ID,int status)
        {
            String query = "UPDATE ProductCategory SET Status=@Status WHERE ID=@ID";
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@Status",status);
            param[1] = new SqlParameter("@ID",ID);
            return this.ExecuteNonQuery(query,param);
        }

        public Boolean UpdateProductCategory(ProductCategoryTO productCategory)
        {
            String query = "UPDATE ProductCategory SET Name=@Name, Status=@Status, UpdateDate=@UpdateDate WHERE ID=@ID";
            SqlParameter[] param=new SqlParameter[4];
            param[0] = new SqlParameter("@Name",productCategory.Name);
            param[1] = new SqlParameter("@UpdateDate",productCategory.UpdateDate);
            param[2] = new SqlParameter("@Status",productCategory.Status);
            param[3] = new SqlParameter("@ID",productCategory.ID);
            return this.ExecuteNonQuery(query,param);
        }
    }
}
